<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

use app\common\model\CoinUsdt;
use app\common\model\ForumBbs;
use app\common\model\ForumBbsComment;

/**
 * 币种逻辑
 */
class Coin extends AdminBase
{
    
    /**
     * 币种分类编辑
     */
    public function coinCategoryEdit($data = [])
    {
        
        $validate_result = $this->validatecoinCategory->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validatecoinCategory->getError()];
        }
        
        $url = url('coinCategoryList');
        
        $result = $this->modelQuotationCoinCategory->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '币种分类' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelQuotationCoinCategory->getError()];
    }
    
    /**
     * 获取币种列表
     */
    public function getcoinList($data = [], $field = 'a.*,m.nickname,c.name as category_name', $order = '')
    {



        if(!empty($data['search_data'])){
            $where['a.coin_a ']=['like','%'.trim($data['search_data']).'%'];
        }
        if(!empty($data['platform_id'])){
            $where['a.platform_id ']=$data['platform_id'];
        }
        if(!empty($data['coin_b'])){
            $where['a.coin_b ']=$data['coin_b'];
        }
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        $count=$this->modelQuotationCoin->alias('a')->where($where)->count();
        $list=$this->modelQuotationCoin->alias('a')->field($field)->where($where)->paginate(50,false,['query'=>$data]);

        return ['list'=>$list,'count'=>$count];
    }

    /**
     * 获取币种列表
     */
    public function getcoinList1($data = [], $field = '*', $order = '')
    {


        $where=[];
        if(!empty($data['search_data'])){
            $where['name|symbol']=['like','%'.$data['search_data'].'%'];
        }
        $count=$this->modelCoinUsdt->where($where)->count();
        $list=$this->modelCoinUsdt->field($field)->where($where)->paginate(50,false,['query'=>$data]);

        return ['list'=>$list,'count'=>$count];
    }


    /**
     * 获取币种列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.name|a.describe'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
    /**
     * 币种信息编辑
     */
    public function coinEdit($data = [])
    {

        $url = url('coin_list1');
       // empty($data['id']) && $data['member_id'] = MEMBER_ID;
        
//      $data['content'] = htmlspecialchars_decode($data['content']);

         $this->modelCoinInfo->where(['symbol'=>$data['symbol']])->update($data);
        $handle_text =  '编辑';
        action_log($handle_text, '币种' . $handle_text);
        
        return  [RESULT_SUCCESS, '币种操作成功', $url] ;
    }

    /**
     * 获取币种信息
     */
    public function getcoinInfo($where = [])
    {
        

        return $this->modelCoinInfo->where($where)->find();
    }
    
    /**
     * 获取分类信息
     */
    public function getcoinCategoryInfo($where = [], $field = true)
    {
        
        return $this->modelQuotationCoinCategory->getInfo($where, $field);
    }
    
    /**
     * 获取币种分类列表
     */
    public function getcoinCategoryList($where = [], $field = true, $order = '', $paginate = 0)
    {
        
        return $this->modelQuotationCoinCategory->getList($where, $field, $order, $paginate);
    }
    
    /**
     * 币种分类删除
     */
    public function coinCategoryDel($where = [])
    {
        
        $result = $this->modelQuotationCoinCategory->deleteInfo($where);
        
        $result && action_log('删除', '币种分类删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '币种分类删除成功'] : [RESULT_ERROR, $this->modelQuotationCoinCategory->getError()];
    }
    
    /**
     * 币种删除
     */
    public function coinDel($where = [])
    {
        
        $result = $this->modelQuotationCoin->deleteInfo($where);
        
        $result && action_log('删除', '币种删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '币种删除成功'] : [RESULT_ERROR, $this->modelQuotationCoin->getError()];
    }

    /**
     * 审核币种
     */
    public function update_info($where = [])
    {


        $result = $this->modelQuotationCoin->setInfo($where);





        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, '操作失败'];
    }





    /**
     * 币种标签编辑
     */
    public function coinTagsEdit($data = [])
    {

        $validate_result = $this->validateExchangeTags->scene('edit')->check($data);

        if (!$validate_result) {

            return [RESULT_ERROR, $this->validateExchangeTags->getError()];
        }

        $url = url('coinTagsList');;
        $result = $this->modelExchangeTags->setInfo($data);

        $handle_text = empty($data['id']) ? '新增' : '编辑';

        $result && action_log($handle_text, '币种标签' . $handle_text . '，name：' . $data['name']);

        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelExchangeTags->getError()];
    }


    /**
     * 获取标签信息
     */
    public function getcoinTagsInfo($where = [], $field = true)
    {

        return $this->modelExchangeTags->getInfo($where, $field);
    }

    /**
     * 获取币种标签列表
     */
    public function getcoinTagsList($where = [], $field = true, $order = '', $paginate = 0)
    {

        return $this->modelExchangeTags->getList($where, $field, $order, $paginate);
    }

    /**
     * 币种标签删除
     */
    public function coinTagsDel($where = [])
    {

        $result = $this->modelExchangeTags->deleteInfo($where);

        $result && action_log('删除', '币种标签删除，where：' . http_build_query($where));

        return $result ? [RESULT_SUCCESS, '币种标签删除成功'] : [RESULT_ERROR, $this->modelExchangeTags->getError()];
    }
}
